package top.raoqq.sky.dto;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import lombok.NoArgsConstructor;
import top.raoqq.sky.entity.sql.Menu;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 饶奇奇
 * @date 2023/8/8
 */
@Data
@NoArgsConstructor
public class MenuDTO {

    @JsonIgnore
    private Long menuId;
    private String path;
    private String name;
    private String component;
    private Map<String, Object> meta;


    /**
     *  菜单标题
     */
    private static final String TITLE = "title";

    /**
     *  菜单是否显示在菜单栏
     */
    private static final String HIDDEN = "hidden";

    /**
     * 菜单组件是否缓存
     */
    private static final String CACHE = "cache";

    /**
     *  菜单图标
     */
    private static final String ICON = "icon";

    /**
     *  菜单类型
     */
    public static final String TYPE = "type";



    private MenuDTO(Long menuId, String path, String name, String component, Map<String, Object> meta) {
        this.menuId = menuId;
        this.path = path;
        this.name = name;
        this.component = component;
        this.meta = meta;
    }

    public static MenuDTO initMenuDTO(Menu menu) {
        Map<String, Object> meta = new HashMap<>(16);
        meta.put(CACHE, menu.getCache().equals(Byte.valueOf("0")));
        meta.put(HIDDEN, menu.getCache().equals(Byte.valueOf("0")));
        meta.put(TITLE, menu.getMenuName());
        meta.put(ICON, menu.getIcon());
        meta.put(TYPE,menu.getMenuType());
        return new MenuDTO(menu.getMenuId(), menu.getPath(), menu.getMenuName(), menu.getComponent(), meta);
    }

    private List<MenuDTO> children;

}
